import cityCascader from "../../../../component/cityCascader/index.vue"
import Bus from "../../bus.js"
export default {
  name: "feedback",
  data() {
    return {
      search: "",
      list: [],
      total: 0,
      form: {
        begintime: "",
        endtime: "",
        pagenum: "1", //查询页码
        pagecount: "1", //当前页面总数
        totalpage: "10", //所有页数
        opinionid: "", //意见建议编码
        username: "", //建议人名称
        content: "", //投诉内容
        telnum: "", //投诉人电话
        pagesize: 10, //页码大小
        totalnum: "", //搜索总数
        createtime: "", //投诉时间
        problemid: "",
        type: "0", //回复tab栏
        citys: [],
        province: "", //省份编码
        city: "", //城市编码
        area: "", //区域编码
        feedbacktype: "1"
      },
      level: "0",
      current: 0, //回复tab栏
      boxTittleType: 1, //个人与企业
      tabs: [{
          label: "待回复",
          type: 0
        },
        {
          label: "已回复",
          type: 1
        },
        {
          label: "无需回复",
          type: 2
        }
      ],
      boxTittle: [{
          label: "个人反馈",
          type: 1
        },
        {
          label: "企业反馈",
          type: 2
        }
      ],
      currentPage: 1
    }
  },
  components: {
    cityCascader
  },
  props: ["type","unread"],
  created() {
    this.form.feedbacktype = this.type
    this.getAuthority()
    this.geteData()
  },
  mounted() {
  },
  activated() {
    this.form.feedbacktype = this.type
    this.getAuthority()
    this.geteData()
    let self = this
    Bus.$on("onload", e => {
      self.geteData()
    })
  },
  methods: {
    getAuthority() {
      let userinfo = localStorage.getItem("userinfo")
      userinfo = JSON.parse(userinfo)
      this.level = userinfo.level
      this.form.province = +userinfo.province || ""
      this.form.city = +userinfo.city || ""
      this.form.area = +userinfo.area || ""
      this.form.citys = []
      this.form.citys.push(+userinfo.province)
      this.form.citys.push(+userinfo.city)
      this.form.citys.push(+userinfo.area)
    },

    geteData() {
      if (
        this.form.begintime &&
        this.form.endtime &&
        Date.parse(this.form.begintime) > Date.parse(this.form.endtime)
      ) {
        this.$message({
          message: "结束时间不能早于开始时间",
          type: "warning"
        })
        return
      }
      this.loading = true
      // /platform / optionList
      this.$axios.$post("/app/v1/platform/option/list", this.form).then(res => {
        console.log(res)
        if (res.data.code === 1) {
          this.list = res.data.data.list || [];
          this.total = parseInt(res.data.data.totalnum);
		  console.log(res.data.data.totalnum);
		  if(this.form.type == 0){this.$emit('update:unread',res.data.data.totalnum)};
          this.loading = false;
        } else {
          this.$message.error(res.data.message)
        }
      })
    },
    toQuery() {
      this.form.pagenum = 1
      this.geteData()
    },
    feedback(obj) {
      this.$router.push({
        path: "./feedback/FeedbackDetails",
        query: {
          opinionid: obj,
          item: 8,
          current: this.current,
          currentType: this.type
        }
      })
    },
    //分页查询
    handleCurrentChange(val) {
      this.form.pagenum = val + ""
      this.geteData()
    },
    handleSizeChange(val) {
      this.form.pagesize = val
      this.form.pagenum = 1
      this.geteData()
    },
    clickTab(item) {
      this.clearData()
      this.current = item.type
      this.form.pagenum = 1
      this.form.pagesize = 10
      this.form.type = item.type
      this.geteData()
    },
    clickTittle(item) {
      this.clearData()
      this.boxTittleType = item.type
      this.form.pagenum = 1
      this.form.pagesize = 10
      this.current = 0
      this.form.type = 0
      this.form.feedbacktype = item.type
      this.geteData()
    },
    // 选择城市
    handleCityChange(val) {
      this.form.citys = val
      this.form.province = val[0]
      this.form.city = val[1]
      this.form.area = val[2]
    },
    clearData() {
      this.form.begintime = ""
      this.form.endtime = ""
      this.form.username = ""
      this.getAuthority()
    }
  },

}